package com.yaorange.utils;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.stereotype.Component;

@Component
public class MailUtils {

    @Autowired
 	private JavaMailSender mailSender;

    @Value("${spring.mail.username}")
    private String from;//读取属性文件获取发送者

    //简单不带附件邮件发送
    public void sendMail(String toAddress, String title, String text) {
        SimpleMailMessage mailMessage = new SimpleMailMessage();
        //设置发件人
        //mailMessage.setFrom("yaorange_test@sina.com");
        mailMessage.setFrom(from);
        //设置收件人
        mailMessage.setTo(toAddress);
        //设置标题
        mailMessage.setSubject(title);
        //设置正文
        mailMessage.setText(text);
        //发送邮件
        mailSender.send(mailMessage);
    }


    //带附件的邮件发送方法


    //使用模板文件的邮件发送方法
}
